#include <stdio.h>
#include <stdlib.h>
#include "tree.h"
#define MAX 50

//preorder visit
void preorder(Node* tree)
{
    if(tree != NULL) {
	printf("%d:%c\n", tree -> index, tree -> value);
	preorder(tree -> leftChild);
	preorder(tree -> rightChild);
    }
}
//preorder visit with stack
void preorder_stack(Node* tree)
{
    Node* p = tree;
    Node* stack[MAX];
    int top = -1;
    printf("preorder visit:\n");
    if(p != NULL) {
	do {
	    while(p != NULL) {
		printf("%d:%c\n", p -> index, p -> value);
		stack[++top] = p;
		p = p -> leftChild;
	    }
	    p = stack[top--];
	    p = p -> rightChild;
	}while(p != NULL || top != -1);
    }
}
